package com.cy.cuiyang_admin.chain;


import com.cy.cuiyang_admin.chain.annotation.AttendHandler;
import com.cy.cuiyang_admin.chain.handler.AttendDetectiveHandler;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author admin
 */
@Component
public class AttendHandlerPostProcessor implements BeanPostProcessor {
    @Resource
    private AttendHandlerChain attendHandlerChain;
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        AttendHandler annotation = bean.getClass().getDeclaredAnnotation(AttendHandler.class);
        if(AttendDetectiveHandler.class.isAssignableFrom(bean.getClass()) && annotation != null){
            attendHandlerChain.registerHandler((AttendDetectiveHandler)bean);
        }
        return bean;
    }
}
